import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class  ClipPathDemo extends StatefulWidget{
  @override
  State<StatefulWidget> createState() =>ClipPathState();
}

class ClipPathState extends State<ClipPathDemo>{
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ClipPath'),
        centerTitle: true,
      ),
      body: ClipPathHome(),


    );

  }

}

class ClipPathHome extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          ClipPath(
            //裁剪路径
            clipper: BottomClipper(),
            child: Container(
              height: 200,
              //double.infinity 和父控件一样大
              width: double.infinity,
              color: Colors.indigoAccent,
            ),
          ),
        ],
      ),
    );
  }

}

/*裁剪路径*/
class BottomClipper extends CustomClipper<Path>{
  @override
  Path getClip(Size size) {
    var path=Path();
    path.lineTo(0, 0);
    path.lineTo(0, size.height-40);

    var firstPoint=Offset(size.width/4, size.height);
    var seconedPoint=Offset(size.width/2, size.height-40);
    path.quadraticBezierTo(firstPoint.dx, firstPoint.dy, seconedPoint.dx, seconedPoint.dy);
    var thirdPoint=Offset(size.width/4*3, size.height-80);
    var fourPoint=Offset(size.width, size.height-40);
    path.quadraticBezierTo(thirdPoint.dx, thirdPoint.dy, fourPoint.dx, fourPoint.dy);

    path.lineTo(size.width, 0);

    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
    return false;
  }


}